import { defineConfig, loadEnv } from 'vite';
import plugins from "./vite.plugin.config";
import build from './vite.build.config';
import server from './vite.server.config';

export default defineConfig(({ mode }) => {
    const env = loadEnv(mode, process.cwd(), 'VITE_');
    
    // ci 传递过来的tag
    const RELEASE = env.RELEASE ?? 'latest';
    const NODE_ENV = env.NODE_ENV ?? 'development';
    const ENV = env.ENV ?? mode;

    return {
        server: server(mode),
        plugins:plugins(mode),
        define: {
            __NODE_ENV__: JSON.stringify(NODE_ENV),
            __MODE__: JSON.stringify(mode),
            __ENV__: JSON.stringify(ENV),
            __RELEASE__: JSON.stringify(RELEASE),
        },
        build: build
    };
});
